package com.movie.demo.controller;

import com.movie.demo.pojo.Cinema;
import com.movie.demo.Utlis.result.CommonResult;
import com.movie.demo.service.CinemaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class CinemaController {
    @Autowired
    private CinemaService cinemaService;
    @PostMapping("/Cinemas")
    public CommonResult<List> select(){
        List<Cinema> movieList = cinemaService.selectCinema();
        if(movieList!=null){
            return CommonResult.success(movieList);
        }
        return CommonResult.failed();
    }
    @PostMapping("/AddCinema")
    public CommonResult add(@RequestBody Cinema cinema){
        Boolean flag=cinemaService.addCinema(cinema);
        if (flag){
            return CommonResult.success(flag);
        }
        return CommonResult.failed();
    }
    @PostMapping("/DeleteCinema")
    public CommonResult Delete(@RequestBody Cinema cinema){
        boolean result=cinemaService.deleteCinema(cinema.getCid());
        if (result) {
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
    @PostMapping("/UpdateCinema")
    public CommonResult Update(@RequestBody Cinema cinema){
        boolean result=cinemaService.updateCinema(cinema);
        if (result) {
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
}
